﻿@{
    ViewBag.Title = "MyPay";
    Layout = "~/Views/Shared/Template.cshtml";
}

<link href="~/static/collect.css" rel="stylesheet" />
<link href="~/static/myhome.css" rel="stylesheet" />

@using Partner.MVC.Models;
@{
    var user = Session["LoginUser"] as User_Info;
}

<div style="height: 300px;width: 100%;background:url(/static/hbweb/images/me.jpg);">
    <div class="container">
        <div class="header-message">
            <img class="fl" src="http://pic.huobanchina.com/o_1bp7omfg8e821pc4bbg1u8g1ifl9.jpeg" alt="" />
            <div class="fl header-text">
                <h3 class="user-name">@user.Use_Name </h3>
                <i class="icon-fabu3 point user-namei"></i>
            </div>
            <a id="AlterPwd" style="width:85px;" data-toggle="modal" data-target="#myModal" class="fr fn-font-hover-blue change change-password">
                修改密码
            </a>
        </div>
    </div>
</div>

<div class="bgcSil">
    <div class="container">
        <div class="mt30" style="width: 100%">
            <ul id="divLeft" style="width:24%" class="nav navbar-nav"></ul>
            <div id="divContent" style="width:75%;" class="fr mb80 cont bgcWhit news-list-con">
                <div class="news-list-con bgcWhit">
                    <div id="myTabContent" class="tab-content">
                        <div class="news-title-tab clearfix">
                            <ul id="myTab" class="nav nav-tabs">
                                <li class="active"><a href="#home" data-toggle="tab">已支付订单</a></li>
                                <li><a href="#country" data-toggle="tab">未支付订单</a></li>
                            </ul>
                        </div>
                        <div class="news-list-con bgcWhit">
                            <div id="myTabContent" class="tab-content">
                                <div class="tab-pane fade in active" id="home">
                                    <div class="news-list-info clearfix">
                                        <ul class="myhome will-delete">
                                            <p><input type="checkbox" onclick="ALL()" />反选&nbsp;&nbsp;<input onclick="DeleteSelection()" type="button" class="btn btn-success" value="删除选中记录" /></p>
                                            @foreach (var a in ViewBag.pay)
                                            {
                                            <li hoseid="@a.Item7.Item1" class="prs">
                                                <div class="fl">
                                                    @{
                                                var zong = a.Item2 * a.Item3;
                                                    }
                                                    <h3>
                                                        <input type="checkbox" name="PayName" value="@a.Item7.Item2" /> 订单名称：<a class="fcBlack" title="@a.Item5"> @a.Item5 </a>
                                                    </h3>
                                                    <p class="p"><span>公司名称：</span>&nbsp;&nbsp;&nbsp;<span>@a.Item4</span></p>
                                                    <p>购买数量 ： @a.Item2  单价： @a.Item3  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  支付总价：@zong</p>
                                                </div>
                                            </li>
                                            }
                                        </ul>
                                    </div>
                                </div>
                                <div class="tab-pane fade" id="country">
                                    <div class="news-list-info clearfix">
                                        <ul class="myhome will-delete">
                                            @foreach (var a in ViewBag.order)
                                            {
                                            <li hoseid="@a.Item7.Item1" class="prs">
                                                <div class="fl">
                                                    @{
                                                var zong = a.Item2 * a.Item3;
                                                    }
                                                    <h3>
                                                        <input id="OrderName" type="checkbox" />  订单名称：<a class="fcBlack" title="@a.Item5"> @a.Item5 </a>
                                                    </h3>
                                                    <p class="p"><span>公司名称：</span>&nbsp;&nbsp;&nbsp;<span>@a.Item4</span></p>
                                                    <p>
                                                        购买数量 ： @a.Item2 &nbsp;&nbsp;&nbsp; 单价： @a.Item3  &nbsp;&nbsp;&nbsp;     支付总价：@zong <button data-toggle="modal" data-target="#PayModel" onclick="GetPayMessage(@a.Item7.Item2)" class="btn btn-success">立即支付</button>
                                                        <button onclick="Delete(@a.Item7.Item1)" class="btn btn-danger">删除此订单</button>
                                                    </p>
                                                </div>
                                            </li>
                                            }
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 模态框 支付密码（Modal） -->
<div class="modal fade" id="PayModel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div style="font-size:16px;" class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">
                    ×
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    您正在支付    &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;
                </h4>
            </div>
            <!--输入支付密码-->
            <div>
                <table id="PayTab">
                    <tr>
                        <td style="font-size:16px;">请输入密码</td>
                        <td><input style="margin-left:66px;" class="form-control" id="PayPwd" type="password" /></td>
                    </tr>
                </table>
            </div>
            <!--代码块结束-->
            <div class="modal-footer">
                <button type="button" class="btn btn-default"
                        data-dismiss="modal">
                    关闭
                </button>
                <button type="button" id="PaySure" class="btn btn-primary">
                    确定
                </button>
                <input type="hidden" id="PayID" />
            </div>
        </div>
    </div>
</div>
<!--修改密码框结束-->
<!-- 左侧导航-->
<script>
    ParentNav();
    // 绑定根节点
    function ParentNav() {
        $.ajax({
            type: "post",
            url: "/Partner/LeftNav",
            dataType: "json",
            success: function (data) {
                var htmltab = "";
                for (var i = 0; i < data.length; i++) {
                    htmltab += "<li class=\"dropdown\"><a href=\"#\" class=\"dropdown-toggle\" data-toggle=\"dropdown\" style=\"width: 175px;font-size: 16px;\">" + data[i].Lar_Name + "</a>" + SonNav(data[i].Limit_Id) + "</li>";
                }
                $("#divLeft").append(htmltab);
            },
            error: function (err) {
                alert(err);
            }
        })
    }
    // 绑定子节点
    function SonNav(id) {
        var html1 = "";
        $.ajax({
            type: "post",
            url: "/Partner/LeftSon",
            data: { pid: id },
            dataType: "json",
            async: false,
            success: function (data) {
                var strhtml = "<ul class=\"dropdown-menu\">"
                for (var i = 0; i < data.length; i++) {
                    strhtml += "<li><a href=\"" + data[i].Limit_Url + "\">" + data[i].Limit_Name + "</a></li>"
                }
                strhtml += "</ul>";
                html1 = strhtml;
            }
        })
        return html1;
    }
</script>

<script>
    //选择银判断余额后进行支付.
    function PayBank(id) {
        //银行卡ID
        var Card = id;
        //服务信息
        var Serve = $("#PayID").val();
        $.ajax({
            type: "Post",
            url: "/UserCenter/PayBank",
            data: { Card: Card, Serve: Serve },
            success: function (i) {
                if (i > 0) {
                    alert("支付成功!");
                    window.location.reload();
                }
                else {
                    alert("银行卡余额不足!请充值!");
                }
            }
        })
    }
    //获取服务的ID
    function GetPayMessage(id) {
        $("#PayID").val(id);
    }
    //输入支付需要的账户密码，进行判断
    $("#PaySure").click(function () {
        var PayPwd = $("#PayPwd").val();
        var PayID = $("#PayID").val();
        if (PayPwd == "") {
            alert("请输入账户密码!");
            return;
        }
        else {
            $.ajax({
                type: "Post",
                url: "/UserCenter/PayMessage",
                data: { PayPwd: PayPwd, PayID: PayID },
                success: function (obj) {
                    if (obj > 0) {
                        GetUserBank();
                    }
                    else {
                        alert("账户密码输入错误!");
                    }
                }
            })
        }
    })
    //密码正确  显示用户的银行卡
    function GetUserBank() {
        $.ajax({
            type: "Post",
            url: "/UserCenter/GetUserBank",
            dataType: "json",
            success: function (obj) {
                obj = eval(obj);
                $("#PayTab").empty();
                for (var i = 0; i < obj.length; i++) {
                    //截取银行卡尾号
                    var Card = obj[i].B_BankAccount;
                    Card = Card.substring(15, Card.length);
                    $("#PayTab").append("  <tr>" +
                        "<td style='font-size:20px;'>您的银行卡:    </td>" +
                        "<td style='font-size:18px;'>" + obj[i].B_BankName + "------尾号:" + Card + "------活期余额为:" + obj[i].B_Balance + "</td><td><input type='button' class='btn btn-success' onclick='PayBank(" + obj[i].B_Id + ")' value='选择支付' /></td>" +
                    "</tr>"
                    )
                }
            }
        })
    }
    //删除订单
    function Delete(id) {
        if (confirm("确定要删除吗？")) {
            $.ajax({
                type: "Post",
                url: "/UserCenter/DeletePay?id=" + id,
                success: function (obj) {
                    if (obj > 0) {
                        window.location.reload();
                    }
                    else {
                        alert("操作失败!");
                    }
                }
            })
        }
        else {
        }
    }
</script>
<!--反选和删除选中的记录!-->
<script>
<!--反选-->
    function ALL() {
        var oSports = document.getElementsByName("PayName");
        for(var i = 0;i < oSports.length;i++){
            oSports[i].checked = !oSports[i].checked; /*将复选框设置为与之前的选择状态相反*/
        }
    }
    //删除选中的已支付的消息
    function DeleteSelection()
    {
        obj = document.getElementsByName("PayName");
        id = "";
        for (var i = 0; i < obj.length; i++)
        {
            if (obj[i].checked)
            {
                id += obj[i].value + ',';
            }
        }
        id = id.substring(0, id.length - 1);
        if(id.length==0){
            alert("请选择要删除的记录!");
        }
        else{
        if (confirm("确定删除选中的信息吗？")) {
            $.ajax({
                type: "Post",
                url: "/UserCenter/DeleteSelection",
                data: { MessageId: id },
                success: function (obj){
                    if (obj > 0) {
                        window.location.reload();
                    }
                    else {
                        alert("操作失败!");
                    }
                }
            })
        }
        }
    }
</script>